package com.my.mymafengwo.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.CameraUpdate;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.BitmapDescriptor;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.services.cloud.CloudItemDetail;
import com.amap.api.services.cloud.CloudResult;
import com.amap.api.services.cloud.CloudSearch;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.example.smallstrong.mafengwopro.R;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.my.mymafengwo.activity.MddActivity;
import com.my.mymafengwo.activity.TravelNotesActivity;
import com.my.mymafengwo.adapter.BaseAdapterHelper;
import com.my.mymafengwo.adapter.LocalPagerAdapter;
import com.my.mymafengwo.adapter.LocalWengsAdapter;
import com.my.mymafengwo.adapter.QuickAdapter;
import com.my.mymafengwo.adapter.RecyclerAdapter;
import com.my.mymafengwo.base.BaseFragment;
import com.my.mymafengwo.bean.Local;
import com.my.mymafengwo.bean.LocalNotice;
import com.my.mymafengwo.utils.DensityUtils;
import com.my.mymafengwo.utils.MathUtils;
import com.my.mymafengwo.utils.UrlUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * ***********************************************
 * author:wgh
 * time:2015/12/3 20:04
 * copyright:
 * name:    当地 Fragment
 * step:
 * ***********************************************
 */
public class LocalFragment extends BaseFragment implements ViewPager.OnPageChangeListener, AdapterView.OnItemClickListener, View.OnClickListener, PopupWindow.OnDismissListener, GeocodeSearch.OnGeocodeSearchListener, CloudSearch.OnCloudSearchListener {

    private static final int NEXT = 0;
    private static final int MOVE = 1;

    //记录当前的网址
    private String nowCity;

    //菜单的列数
    private static final int NUMCOLUMNS = 4;
    //每面菜单的个数
    private static final int NUMMENUS = 8;
    //当地页面对象
    private View view;
    //本页面数据
    private Local local;
    //周边推荐数据
    private LocalNotice notice;
    private List<LocalNotice.DataEntity.ListEntity.PoisEntity> pois;
    //顶部下拉按钮
    private TextView tvTop;
    //
    private PopupWindow popupWindow;
    //声明popupwindow布局对象
    private View pwView;
    //声明popupwindow按键选择对象
    private Button btnSH, btnBJ, btnHZ, btnNB;
    //屏幕宽度
    private int screenW;
    //声明当地蜜蜂数量布局,进入目的地
    private TextView tvNum, tvMdd;
    //当地页面上方滚动菜单
    private ViewPager viewPager;
    //声明当地页面滚动菜单下部小点的布局
    private LinearLayout llPoint;
    //用于存储小点对象的列表
    private List<View> pointList;

    //声明地图右上角定位按钮
    private ImageView ivMap;
    //声明地图右上角定位结果文字布局
    private TextView tvMap;
    //声明地图布局
    private MapView mapView;
    private AMap aMap;
    //声明AMapLocationClient类对象
    private AMapLocationClient mLocationClient = null;
    //声明定位回调监听器
    private AMapLocationListener mLocationListener = null;
    //声明mLocationOption对象
    private AMapLocationClientOption mLocationOption = null;
    //获取到的经纬度
    private double mLat, mLng;
    //用于地理编码
    private GeocodeSearch mGeocodeSearch;
    //
    private CloudSearch mCloudSearch;
    //
    private int mTableID;
    private CloudSearch.Query cloudQuery;
    //周边推荐图标
    private List<Integer> mapPoiList;
    //周边推荐 显示在地图上的图标
    private List<Integer> mapPointList;
    //存储地图标记对象
    private Marker marker;
    //周边推荐类型
    private int noticeType;
    //声明周边推荐布局
    private ViewFlipper vfNotice;
    private int mCurrPos;
    //特色当地游的
    private List<GridView> gridViewList;
    //菜单栏ViewPager的适配器
    private LocalPagerAdapter pagerAdapter;
    //用于记录上方菜单栏当前页面的下标
    private int pageIndex = 0;
    //上方菜单GridView的快速适配器
    private QuickAdapter<Local.DataEntity.IconsEntity> gridViewAdapter;
    //声明(正在发生)的布局
    private GridView gvWengs;
    //(正在发生)的快速适配器
    private QuickAdapter<Local.DataEntity.WengsEntity.ListEntity> wengsGridViewAdapter;
    private LocalWengsAdapter wengsAdapter;
    //声明特色当地游列表控件
    private RecyclerView rvProduct;
    //特色当地游的适配器
    private RecyclerAdapter recyclerAdapter;
    private RecyclerView.LayoutManager mLayoutManager;

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
                case NEXT:
                    moveToNext();
                    handler.sendEmptyMessageDelayed(NEXT, 4000);
                    break;
                case MOVE:
                    moveMap();
                    handler.sendEmptyMessageDelayed(MOVE, 2000);
                    break;
            }

        }
    };

    @Override
    protected View initView() {
        view = View.inflate(getActivity(), R.layout.fragment_local, null);
        pwView = LayoutInflater.from(mActivity).inflate(R.layout.city_popupwindow, null);
        return view;
    }

    @Override
    protected void initData() {
        findViews();
        initTopSpinner();
        registerListener();
        downloadData(UrlUtils.LOCAL_URL_SH, UrlUtils.LOCAL_NOTICE_SH, "上海");
    }

    private void registerListener() {

        ivMap.setOnClickListener(this);
        tvMdd.setOnClickListener(this);

    }


    /**
     * 查找控件
     */
    private void findViews() {
        tvTop = (TextView) view.findViewById(R.id.tv_local_top);

        tvNum = (TextView) view.findViewById(R.id.tv_local_num);
        viewPager = (ViewPager) view.findViewById(R.id.vp_local);
        llPoint = (LinearLayout) view.findViewById(R.id.ll_local_point);

        ivMap = (ImageView) view.findViewById(R.id.iv_local_map_gps);
        tvMap = (TextView) view.findViewById(R.id.tv_local_map);
        mapView = (MapView) view.findViewById(R.id.mapview_local);
        vfNotice = (ViewFlipper) view.findViewById(R.id.vf_local_notice);

        gvWengs = (GridView) view.findViewById(R.id.gv_local_wengs);
        rvProduct = (RecyclerView) view.findViewById(R.id.rv_local_products);

        btnSH = (Button) pwView.findViewById(R.id.btn_sh);
        btnBJ = (Button) pwView.findViewById(R.id.btn_bj);
        btnHZ = (Button) pwView.findViewById(R.id.btn_hz);
        btnNB = (Button) pwView.findViewById(R.id.btn_nb);

        tvMdd = (TextView) view.findViewById(R.id.tv_local_mdd);
    }


    /**
     * 初始化顶部下拉菜单
     */
    private void initTopSpinner() {
        DisplayMetrics metrics = new DisplayMetrics();
        mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        screenW = metrics.widthPixels;
        tvTop.setOnClickListener(this);
        btnSH.setOnClickListener(this);
        btnBJ.setOnClickListener(this);
        btnHZ.setOnClickListener(this);
        btnNB.setOnClickListener(this);
    }

    /**
     * 下载数据
     *
     * @param url 下载数据的网址
     */
    private void downloadData(String url, String noticeUrl, String city) {
        if (popupWindow != null) {
            popupWindow.dismiss();
        }
        HttpUtils http = new HttpUtils();
        if (!city.equals(nowCity)) {
            http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    String result = responseInfo.result;
                    if (result != null) {
                        try {
                            local = new Gson().fromJson(result, Local.class);
                        } catch (JsonSyntaxException e) {
                            e.printStackTrace();
                        }
                        if (local != null) {
                            loadData();
                        }
                    }
                }

                @Override
                public void onFailure(HttpException e, String s) {
                    Toast.makeText(getActivity(), "网络异常，请检查网络。", Toast.LENGTH_SHORT).show();
                }
            });

            nowCity = city;
        }
        if (noticeUrl != null) {
            //下载周边推荐的内容
            http.send(HttpRequest.HttpMethod.GET, noticeUrl, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    if (responseInfo.result != null) {
                        try {
                            notice = new Gson().fromJson(responseInfo.result, LocalNotice.class);
                        } catch (JsonSyntaxException e) {
                            e.printStackTrace();
                        }
                    }

                    if (notice != null) {
                        handler.sendEmptyMessage(MOVE);
                        if (pois != null) {
                            pois.clear();
                            mCurrPos = 0;
                            handler.removeMessages(NEXT);
                        }
                        try {
                            pois = notice.getData().getList().get(0).getPois();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        handler.sendEmptyMessage(NEXT);
                    }
                }

                @Override
                public void onFailure(HttpException e, String s) {

                }
            });
        }
    }

    /**
     * 把地图可视区域移动到指定位置
     */

    private void moveMap() {
        CameraUpdate update = CameraUpdateFactory.changeLatLng(new LatLng(notice.getData().getS_mdd().getLat(), notice.getData().getS_mdd().getLng()));
        if (aMap != null) {
            aMap.animateCamera(update, 1000, new AMap.CancelableCallback() {
                @Override
                public void onFinish() {
                    handler.removeMessages(MOVE);
                }

                @Override
                public void onCancel() {

                }
            });
        }
    }

    /**
     * 周边推荐-加载下一项
     */
    private void moveToNext() {
        setView(mCurrPos, mCurrPos + 1);
        vfNotice.setInAnimation(mActivity, R.anim.in_bottomtop);
        vfNotice.setOutAnimation(mActivity, R.anim.out_bottomtop);
        vfNotice.showNext();
    }

    /**
     * 加载下一个推荐
     *
     * @param curr
     * @param next
     */
    private void setView(int curr, int next) {
        View noticeView = view.inflate(mActivity, R.layout.item_viewflipper_local, null);
        ImageView ivNotice = (ImageView) noticeView.findViewById(R.id.iv_local_notice);
        TextView tvNotice = (TextView) noticeView.findViewById(R.id.tv_local_notice);
        TextView tvNoticeDis = (TextView) noticeView.findViewById(R.id.tv_local_notice_distance);
        if ((curr < next) && (next > pois.size() - 1)) {
            next = 0;
        } else if ((curr > next) && (next) < 0) {
            next = pois.size() - 1;
        }
        noticeType = pois.get(next).getType_id();
        if (mapPoiList != null) {
            ivNotice.setImageResource(mapPoiList.get(noticeType));
            showMapPoint(next);
        }
        tvNotice.setText(pois.get(next).getName());
        int dis = MathUtils.getAMapDistance(new LatLng(mLat, mLng), new LatLng(pois.get(next).getLat(), pois.get(next).getLng()));
        if (dis < 1000) {
            tvNoticeDis.setText("距你" + dis + "m");
        } else {
            tvNoticeDis.setText("距你" + dis / 100 / 10.0 + "km");
        }
//        tvNoticeDis.setText("距你" + MathUtils.getOneDouble(MathUtils.getDistance(mLat, mLng, pois.get(next).getLat(), pois.get(next).getLng())) + "km");
        vfNotice.setOnClickListener(this);
        if (vfNotice.getChildCount() > 1) {
            vfNotice.removeViewAt(0);
        }
        vfNotice.addView(noticeView, vfNotice.getChildCount());
        mCurrPos = next;
    }

    /**
     * 显示周边推荐地点在地图上的坐标
     *
     * @param next
     */
    private void showMapPoint(int next) {
        BitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(mapPointList.get(noticeType));
        if (aMap != null) {
            if (marker != null)
                marker.remove();
            marker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
                            .position(new LatLng(pois.get(next).getLat(), pois.get(next).getLng()))
                            .draggable(false)
                            .icon(descriptor)
            );
            marker.showInfoWindow();

        }
    }

    /**
     * 把数据加载到界面上
     */
    private void loadData() {
        tvNum.setText(local.getData().getNum_url().getNum() + "");
        loadMenuData();
        loadMap();
        loadWengsData();
        loadProductData();
    }


    /**
     * 加载上方菜单部分数据
     */
    private void loadMenuData() {
        llPoint.removeAllViews();
        //加载GridView的适配器
        pagerAdapter = new LocalPagerAdapter(mActivity, gridViewList);
        viewPager.setAdapter(pagerAdapter);
        gridViewList = new ArrayList<>();
        pointList = new ArrayList<>();
        //数据源的数量
        int size = local.getData().getIcons().size();
        for (int i = 0; i <= size / NUMMENUS; i++) {
            //创建GridView布局
            GridView gridView = new GridView(mActivity);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            gridView.setNumColumns(NUMCOLUMNS);
            gridView.setLayoutParams(params);
            gridViewAdapter = new QuickAdapter<Local.DataEntity.IconsEntity>(mActivity, R.layout.list_item_of_main_icon, local.getData().getIcons().subList(NUMMENUS * i, NUMMENUS * (i + 1) < size ? NUMMENUS * (i + 1) : size)) {
                @Override
                protected void convert(BaseAdapterHelper helper, Local.DataEntity.IconsEntity item) {
                    helper.setText(R.id.ItemText, item.getTitle());
                    helper.setImageUrl(R.id.ItemImage, item.getIcon());
                }
            };
            gridView.setAdapter(gridViewAdapter);
            gridViewList.add(gridView);
            //动态加载小圆点
            View view = new View(mActivity);
            LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(15, 15);
            params1.setMargins(5, 0, 5, 10);
            view.setLayoutParams(params1);
            view.setBackgroundResource(R.drawable.selector_local_point);
            if (i == 0) {
                view.setEnabled(true);
            } else {
                view.setEnabled(false);
            }
            llPoint.addView(view);
            pointList.add(view);

            gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    intoWebActivity(local.getData().getIcons().get(position + NUMMENUS * pageIndex).getJump_url());
                }
            });
        }

        pagerAdapter.setData(gridViewList);
        pagerAdapter.notifyDataSetChanged();

        viewPager.addOnPageChangeListener(this);
    }

    /**
     * 初始化地图对象
     */
    private void loadMap() {
        initMapData();
        mapView.onCreate(savedInstanceState);
        aMap = mapView.getMap();
        initAMap();
        mLocationClient.startLocation();
    }

    /**
     * 初始化地图资源数据
     */
    private void initMapData() {
        mapPoiList = new ArrayList<>();
        mapPoiList.add(R.mipmap.ic_poi_type_0);
        mapPoiList.add(R.mipmap.ic_poi_type_1);
        mapPoiList.add(R.mipmap.ic_poi_type_2);
        mapPoiList.add(R.mipmap.ic_poi_type_3);
        mapPoiList.add(R.mipmap.ic_poi_type_4);
        mapPoiList.add(R.mipmap.ic_poi_type_5);
        mapPoiList.add(R.mipmap.ic_poi_type_6);
        mapPointList = new ArrayList<>();
        mapPointList.add(R.mipmap.ic_point_0);
        mapPointList.add(R.mipmap.ic_point_1);
        mapPointList.add(R.mipmap.ic_point_2);
        mapPointList.add(R.mipmap.ic_point_3);
        mapPointList.add(R.mipmap.ic_point_4);
        mapPointList.add(R.mipmap.ic_point_5);
        mapPointList.add(R.mipmap.ic_point_6);
    }


    /**
     * 获取定位地图数据
     */
    private void initAMap() {
        //初始化定位
        mLocationClient = new AMapLocationClient(mActivity.getApplicationContext());
        mLocationListener = new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation aMapLocation) {
                if (aMapLocation != null) {
                    if (aMapLocation.getErrorCode() == 0) {
                        double tag = mLat;
                        //纬度
                        mLat = aMapLocation.getLatitude();
                        //经度
                        mLng = aMapLocation.getLongitude();
                        loadGps();
                        if (tag == 0) {
                            loadWengsData();
                            loadGps();
//                            loadCloudSearch();
                        }
                        if (mLocationClient != null) {
                            //定位完成，停止定位
                            mLocationClient.stopLocation();
                        }
                    }

                }
            }
        };
        mLocationClient.setLocationListener(mLocationListener);

        mLocationOption = new AMapLocationClientOption();
        //设置定位模式为高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //设置是否返回地址信息（默认返回地址信息）
        mLocationOption.setNeedAddress(true);
        //设置是否只定位一次,默认为false
        mLocationOption.setOnceLocation(false);
        //设置是否强制刷新WIFI，默认为强制刷新
        mLocationOption.setWifiActiveScan(true);
        //设置是否允许模拟位置,默认为false，不允许模拟位置
        mLocationOption.setMockEnable(false);
        //设置定位间隔,单位毫秒,默认为2000ms
        mLocationOption.setInterval(2000);
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
        //启动定位

    }

    /**
     * 查询周边
     */
    private void loadCloudSearch() {
        mCloudSearch = new CloudSearch(mActivity);// 初始化查询类
        mCloudSearch.setOnCloudSearchListener(this);// 设置回调函数
        // 设置中心点及检索范围
        CloudSearch.SearchBound bound = new CloudSearch.SearchBound(new LatLonPoint(
                mLat, mLng), 4000);
        //设置查询条件 mTableID是将数据存储到数据管理台后获得。
        try {
            cloudQuery = new CloudSearch.Query(mTableID + "", "公园", bound);
        } catch (AMapException e) {
            e.printStackTrace();
        }
        mCloudSearch.searchCloudAsyn(cloudQuery);

    }


    /**
     * 定位-逆地理编码
     */
    private void loadGps() {
        mGeocodeSearch = new GeocodeSearch(mActivity);
        mGeocodeSearch.setOnGeocodeSearchListener(this);
        LatLonPoint point = new LatLonPoint(mLat, mLng);
        //latLonPoint参数表示一个Latlng，第二参数表示范围多少米，GeocodeSearch.AMAP表示是国测局坐标系还是GPS原生坐标系
        RegeocodeQuery query = new RegeocodeQuery(point, 1000, GeocodeSearch.AMAP);
        mGeocodeSearch.getFromLocationAsyn(query);
    }

    /**
     * 加载正在发生数据
     */
    private void loadWengsData() {
        wengsAdapter = new LocalWengsAdapter(mActivity, local.getData().getWengs().getList(), mLat, mLng);
        gvWengs.setAdapter(wengsAdapter);
        wengsAdapter.notifyDataSetChanged();
        gvWengs.setOnItemClickListener(this);
    }

    /**
     * 加载特色当地游部分数据
     */

    private void loadProductData() {
//        rvProduct.setLayoutManager(new LinearLayoutManager(mActivity));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtils.dp2px(mActivity, 130 * local.getData().getProducts().getList().size()));
        rvProduct.setLayoutParams(params);
        mLayoutManager = new LinearLayoutManager(mActivity);
        rvProduct.setLayoutManager(mLayoutManager);
        recyclerAdapter = new RecyclerAdapter(mActivity, local.getData().getProducts().getList());
        rvProduct.setAdapter(recyclerAdapter);

        recyclerAdapter.notifyDataSetChanged();

        recyclerAdapter.setOnItemClickListener(new RecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                intoWebActivity(local.getData().getProducts().getList().get(position).getJump_url());
            }
        });
    }


    /**
     * 进入WebView界面
     *
     * @param url 跳转的网址
     */
    private void intoWebActivity(String url) {

        Intent intent = new Intent(mActivity, TravelNotesActivity.class);
        intent.putExtra("url", url);
        startActivity(intent);

    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    /**
     * ViewPager滚动的监听
     *
     * @param position
     */
    @Override
    public void onPageSelected(int position) {
        for (int i = 0; i < pointList.size(); i++) {
            if (i == position) {
                pointList.get(i).setEnabled(true);
            } else {
                pointList.get(i).setEnabled(false);
            }
        }
        pageIndex = position;
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (parent.getId()) {
            case R.id.gv_local_wengs:
                intoWebActivity(local.getData().getWengs().getJump_url());
                break;
        }
    }

    @Override
    public void onClick(View v) {
//        System.out.println(v.getId() + "..." + R.id.);
        switch (v.getId()) {
            case R.id.tv_local_top://显示popupwindow窗口
                popupWindow = new PopupWindow(pwView, screenW / 3, LinearLayout.LayoutParams.WRAP_CONTENT);
                WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
                params.alpha = 0.7f;
                mActivity.getWindow().setAttributes(params);

                popupWindow.setFocusable(true);
                popupWindow.setBackgroundDrawable(new ColorDrawable(Color.BLUE));
                popupWindow.setOutsideTouchable(true);
//                popupWindow.showAsDropDown(tvTop);
                popupWindow.showAsDropDown(tvTop, DensityUtils.dp2px(mActivity, -10), 0);
                popupWindow.setOnDismissListener(this);

                break;
            case R.id.btn_sh:
                tvTop.setText("上海");
                downloadData(UrlUtils.LOCAL_URL_SH, UrlUtils.LOCAL_NOTICE_SH, "上海");
                break;
            case R.id.btn_bj:
                tvTop.setText("北京");
                downloadData(UrlUtils.LOCAL_URL_BJ, UrlUtils.LOCAL_NOTICE_BJ, "北京");
                break;
            case R.id.btn_hz:
                tvTop.setText("杭州");
                downloadData(UrlUtils.LOCAL_URL_HZ, UrlUtils.LOCAL_NOTICE_HZ, "杭州");
                break;
            case R.id.btn_nb:
                tvTop.setText("宁波");
                downloadData(UrlUtils.LOCAL_URL_NB, UrlUtils.LOCAL_NOTICE_NB, "宁波");
                break;

            case R.id.iv_local_map_gps:
                if (mLocationClient != null && !mLocationClient.isStarted()) {
                    mLocationClient.startLocation();
                    loadGps();
                }
                Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.local_map_reflash);
                ivMap.startAnimation(animation);
                break;
            case R.id.vf_local_notice:
                intoWebActivity(pois.get(mCurrPos).getJump_url());
                break;
            case R.id.tv_local_mdd://点击进入目的地
                Intent intent = new Intent(mActivity, MddActivity.class);
                intent.putExtra("city", nowCity);
                startActivity(intent);
                break;
            default:
                break;
        }
    }


    @Override
    public void onDismiss() {
        WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
        params.alpha = 1;
        mActivity.getWindow().setAttributes(params);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mLocationClient != null) {
            mLocationClient.onDestroy();
        }
    }

    /**
     * 逆地理编码回调接口
     *
     * @param regeocodeResult
     * @param i
     */
    @Override
    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
        //解析result获取逆地理编码结果
        if (i == 0) {
            tvMap.setText(regeocodeResult.getRegeocodeAddress().getFormatAddress());
        }
    }

    @Override
    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {

    }

    /**
     * 云检索的接口回调
     *
     * @param cloudResult
     * @param i
     */
    @Override
    public void onCloudSearched(CloudResult cloudResult, int i) {
    }

    @Override
    public void onCloudItemDetailSearched(CloudItemDetail cloudItemDetail, int i) {

    }


}
